home *** CD-ROM | disk | FTP | other *** search
/ Aminet 16 / Aminet 16 (1996)(GTI - Schatztruhe)[!][Dec 1996].iso / Aminet / dev / src / wangisrc.lha / wangi / z / wpad_library / WPP_Entry.c < prev    next >
C/C++ Source or Header  |  1995-08-28  |  3KB  |  119 lines

  1. /***************************************************************************
  2.  * WPP_Entry.c
  3.  *
  4.  * wpad.library, Copyright ©1995 Lee Kindness.
  5.  *
  6.  * WPP_Entry()
  7.  */
  8.  
  9. #include "wpad_global.h"
  10.  
  11. VOID LIBENT WPP_Entry( VOID )
  12. {
  13.     struct Process *proc;
  14.     struct Pad *pad;
  15.     
  16.     /* Protect us from the library disapearing! */
  17.     ObtainSemaphoreShared(&EntrySem);
  18.     
  19.     /* Fing our process block */
  20.     proc = (struct Process *)FindTask(NULL);
  21.     
  22.     /* Retrieve the Pad structure which was hidden using the NP_ExitData tag */
  23.     pad = (struct Pad *)proc->pr_ExitData;
  24.     
  25.     /* A wee message */
  26.     Printf("Hello from process \"%s\" 0x%06lx\n", ((struct Node *)proc)->ln_Name, pad);
  27.     
  28.     /* Open a message port */
  29.     if( pad->pad_MsgPort = CreateMsgPort() )
  30.     {
  31.         ULONG pmpsig, cxsig, winsig, signal;
  32.         BOOL ABORT;
  33.         ABORT = FALSE;
  34.  
  35.         WPP_AllocPIHandles(pad);
  36.         WPP_AddHotKeys(pad);
  37.         WPP_OpenWindow(pad);
  38.         
  39.         for(;;)
  40.         {
  41.             signal = Wait(WPP_GetSigMask(pad, &pmpsig, &cxsig, &winsig));
  42.             
  43.             if( signal & pmpsig )
  44.             {
  45.                 struct WPMsg *wpmsg;
  46.                 Printf("Message to Pad->pad_MsgPort\n");
  47.                 while( wpmsg = (struct WPMsg *)GetMsg(pad->pad_MsgPort) )
  48.                 {
  49.                     switch( wpmsg->wpm_Action )
  50.                     {
  51.                         case WPM_ACTION_DIE:
  52.                             Printf("WPM_ACTION_DIE\n");
  53.                             ABORT = TRUE;
  54.                             Printf("Bye from process \"%s\" 0x06%lx\n", ((struct Node *)proc)->ln_Name, pad);
  55.                             WPP_FreeHotKeys(pad);
  56.                             WPP_CloseWindow(pad);
  57.                             WPP_FreePIHandles(pad);
  58.                             break;
  59.                         case WPM_ACTION_GETATTRS:
  60.                             Printf("WPM_ACTION_GETATTRS\n");
  61.                             break;
  62.                         case WPM_ACTION_SETATTRS:
  63.                             Printf("WPM_ACTION_SETATTRS\n");
  64.                             break;    
  65.                     }
  66.                     ReplyMsg(wpmsg);
  67.                 }
  68.             }
  69.             
  70.             if( signal & cxsig )
  71.             {
  72.                 CxMsg *msg;
  73.                 ULONG msgtype, msgid;
  74.                 
  75.                 Printf("Message to Pad->pad_CxMsgPort\n");
  76.                 while( msg = (CxMsg *)GetMsg(pad->pad_CxMsgPort) )
  77.                 {
  78.                     msgtype = CxMsgType(msg);
  79.                     msgid = CxMsgID(msg);
  80.                     ReplyMsg((struct Message *)msg);
  81.                     if( msgtype == CXM_IEVENT )
  82.                     {
  83.                         if( msgid )
  84.                         {
  85.                             if( msgid == EVENT_MAINHOTKEY )
  86.                                 Printf("EVENT_MAINHOTKEY\n");
  87.                             else
  88.                             {
  89.                                 if( pad->pad_Hook )
  90.                                 {
  91.                                     struct WPOPHookMsg *hmsg;
  92.                                     if( hmsg = AllocVec(sizeof(struct WPOPHookMsg), MEMF_CLEAR) )
  93.                                     {
  94.                                         hmsg->hm_MethodID = WPOP_HOOK_EXEC;
  95.                                         CallHookPkt(pad->pad_Hook, hmsg, (APTR)msgid);
  96.                                         FreeVec(hmsg);
  97.                                     }
  98.                                 }
  99.                             }
  100.                         }
  101.                     }
  102.                 }
  103.             }
  104.             
  105.             if( ABORT )
  106.                 break;
  107.         }
  108.         DeleteMsgPort(pad->pad_MsgPort);
  109.     }
  110.     
  111.     /* Free the pad structure */
  112.     CloseFont(pad->pad_TFont);
  113.     FreeVec(pad);
  114.     
  115.     ReleaseSemaphore(&EntrySem);
  116.     
  117.     /* This process has been terminated... :) */
  118. }
  119.